<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html lang="en">

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>LCOV - id:000977,sync:fuzzer2,src:001052.lcov_info_final - src/scanscalar.cpp</title>
  <link rel="stylesheet" type="text/css" href="../gcov.css">
</head>

<body>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="title">LCOV - code coverage report</td></tr>
    <tr><td class="ruler"><img src="../glass.png" width=3 height=3 alt=""></td></tr>

    <tr>
      <td width="100%">
        <table cellpadding=1 border=0 width="100%">
          <tr>
            <td width="10%" class="headerItem">Current view:</td>
            <td width="35%" class="headerValue"><a href="../index.html">top level</a> - <a href="index.html">src</a> - scanscalar.cpp<span style="font-size: 80%;"> (source / <a href="scanscalar.cpp.func-sort-c.html">functions</a>)</span></td>
            <td width="5%"></td>
            <td width="15%"></td>
            <td width="10%" class="headerCovTableHead">Hit</td>
            <td width="10%" class="headerCovTableHead">Total</td>
            <td width="15%" class="headerCovTableHead">Coverage</td>
          </tr>
          <tr>
            <td class="headerItem">Test:</td>
            <td class="headerValue">id:000977,sync:fuzzer2,src:001052.lcov_info_final</td>
            <td></td>
            <td class="headerItem">Lines:</td>
            <td class="headerCovTableEntry">128</td>
            <td class="headerCovTableEntry">128</td>
            <td class="headerCovTableEntryHi">100.0 %</td>
          </tr>
          <tr>
            <td class="headerItem">Date:</td>
            <td class="headerValue">2016-03-13 10:42:47</td>
            <td></td>
            <td class="headerItem">Functions:</td>
            <td class="headerCovTableEntry">3</td>
            <td class="headerCovTableEntry">3</td>
            <td class="headerCovTableEntryHi">100.0 %</td>
          </tr>
          <tr><td><img src="../glass.png" width=3 height=3 alt=""></td></tr>
        </table>
      </td>
    </tr>

    <tr><td class="ruler"><img src="../glass.png" width=3 height=3 alt=""></td></tr>
  </table>

  <table cellpadding=0 cellspacing=0 border=0>
    <tr>
      <td><br></td>
    </tr>
    <tr>
      <td>
<pre class="sourceHeading">          Line data    Source code</pre>
<pre class="source">
<a name="1"><span class="lineNum">       1 </span>            : #include &quot;scanscalar.h&quot;</a>
<span class="lineNum">       2 </span>            : 
<span class="lineNum">       3 </span>            : #include &lt;algorithm&gt;
<span class="lineNum">       4 </span>            : 
<span class="lineNum">       5 </span>            : #include &quot;exp.h&quot;
<span class="lineNum">       6 </span>            : #include &quot;regeximpl.h&quot;
<span class="lineNum">       7 </span>            : #include &quot;stream.h&quot;
<span class="lineNum">       8 </span>            : #include &quot;yaml-cpp/exceptions.h&quot;  // IWYU pragma: keep
<span class="lineNum">       9 </span>            : 
<span class="lineNum">      10 </span>            : namespace YAML {
<span class="lineNum">      11 </span>            : // ScanScalar
<span class="lineNum">      12 </span>            : // . This is where the scalar magic happens.
<span class="lineNum">      13 </span>            : //
<span class="lineNum">      14 </span>            : // . We do the scanning in three phases:
<span class="lineNum">      15 </span>            : //   1. Scan until newline
<span class="lineNum">      16 </span>            : //   2. Eat newline
<span class="lineNum">      17 </span>            : //   3. Scan leading blanks.
<span class="lineNum">      18 </span>            : //
<a name="19"><span class="lineNum">      19 </span>            : // . Depending on the parameters given, we store or stop</a>
<span class="lineNum">      20 </span>            : //   and different places in the above flow.
<span class="lineNum">      21 </span><span class="lineCov">      33038 : std::string ScanScalar(Stream&amp; INPUT, ScanScalarParams&amp; params) {</span>
<span class="lineNum">      22 </span><span class="lineCov">      33038 :   bool foundNonEmptyLine = false;</span>
<span class="lineNum">      23 </span><span class="lineCov">      33038 :   bool pastOpeningBreak = (params.fold == FOLD_FLOW);</span>
<span class="lineNum">      24 </span><span class="lineCov">      33038 :   bool emptyLine = false, moreIndented = false;</span>
<span class="lineNum">      25 </span><span class="lineCov">      33038 :   int foldedNewlineCount = 0;</span>
<span class="lineNum">      26 </span><span class="lineCov">      33038 :   bool foldedNewlineStartedMoreIndented = false;</span>
<span class="lineNum">      27 </span><span class="lineCov">      33038 :   std::size_t lastEscapedChar = std::string::npos;</span>
<span class="lineNum">      28 </span><span class="lineCov">      33038 :   std::string scalar;</span>
<span class="lineNum">      29 </span><span class="lineCov">      33038 :   params.leadingSpaces = false;</span>
<span class="lineNum">      30 </span>            : 
<span class="lineNum">      31 </span><span class="lineCov">      33038 :   if (!params.end) {</span>
<span class="lineNum">      32 </span><span class="lineCov">        477 :     params.end = &amp;Exp::Empty();</span>
<span class="lineNum">      33 </span>            :   }
<span class="lineNum">      34 </span>            : 
<span class="lineNum">      35 </span><span class="lineCov">      54284 :   while (INPUT) {</span>
<span class="lineNum">      36 </span>            :     // ********************************
<span class="lineNum">      37 </span>            :     // Phase #1: scan until line ending
<span class="lineNum">      38 </span>            : 
<span class="lineNum">      39 </span><span class="lineCov">      43476 :     std::size_t lastNonWhitespaceChar = scalar.size();</span>
<span class="lineNum">      40 </span><span class="lineCov">      43476 :     bool escapedNewline = false;</span>
<span class="lineNum">      41 </span><span class="lineCov">    1748456 :     while (!params.end-&gt;Matches(INPUT) &amp;&amp; !Exp::Break().Matches(INPUT)) {</span>
<span class="lineNum">      42 </span><span class="lineCov">     853934 :       if (!INPUT)</span>
<span class="lineNum">      43 </span><span class="lineCov">        336 :         break;</span>
<span class="lineNum">      44 </span>            : 
<span class="lineNum">      45 </span>            :       // document indicator?
<span class="lineNum">      46 </span><span class="lineCov">     853598 :       if (INPUT.column() == 0 &amp;&amp; Exp::DocIndicator().Matches(INPUT)) {</span>
<span class="lineNum">      47 </span><span class="lineCov">        677 :         if (params.onDocIndicator == BREAK)</span>
<span class="lineNum">      48 </span><span class="lineCov">        675 :           break;</span>
<span class="lineNum">      49 </span><span class="lineCov">          2 :         else if (params.onDocIndicator == THROW)</span>
<span class="lineNum">      50 </span><span class="lineCov">          2 :           throw ParserException(INPUT.mark(), ErrorMsg::DOC_IN_SCALAR);</span>
<span class="lineNum">      51 </span>            :       }
<span class="lineNum">      52 </span>            : 
<span class="lineNum">      53 </span><span class="lineCov">     852921 :       foundNonEmptyLine = true;</span>
<span class="lineNum">      54 </span><span class="lineCov">     852921 :       pastOpeningBreak = true;</span>
<span class="lineNum">      55 </span>            : 
<span class="lineNum">      56 </span>            :       // escaped newline? (only if we're escaping on slash)
<span class="lineNum">      57 </span><span class="lineCov">     852921 :       if (params.escape == '\\' &amp;&amp; Exp::EscBreak().Matches(INPUT)) {</span>
<span class="lineNum">      58 </span>            :         // eat escape character and get out (but preserve trailing whitespace!)
<span class="lineNum">      59 </span><span class="lineCov">        109 :         INPUT.get();</span>
<span class="lineNum">      60 </span><span class="lineCov">        109 :         lastNonWhitespaceChar = scalar.size();</span>
<span class="lineNum">      61 </span><span class="lineCov">        109 :         lastEscapedChar = scalar.size();</span>
<span class="lineNum">      62 </span><span class="lineCov">        109 :         escapedNewline = true;</span>
<span class="lineNum">      63 </span><span class="lineCov">        109 :         break;</span>
<span class="lineNum">      64 </span>            :       }
<span class="lineNum">      65 </span>            : 
<span class="lineNum">      66 </span>            :       // escape this?
<span class="lineNum">      67 </span><span class="lineCov">     852812 :       if (INPUT.peek() == params.escape) {</span>
<span class="lineNum">      68 </span><span class="lineCov">       8554 :         scalar += Exp::Escape(INPUT);</span>
<span class="lineNum">      69 </span><span class="lineCov">       8232 :         lastNonWhitespaceChar = scalar.size();</span>
<span class="lineNum">      70 </span><span class="lineCov">       8232 :         lastEscapedChar = scalar.size();</span>
<span class="lineNum">      71 </span><span class="lineCov">       8232 :         continue;</span>
<span class="lineNum">      72 </span>            :       }
<span class="lineNum">      73 </span>            : 
<span class="lineNum">      74 </span>            :       // otherwise, just add the damn character
<span class="lineNum">      75 </span><span class="lineCov">     844258 :       char ch = INPUT.get();</span>
<span class="lineNum">      76 </span><span class="lineCov">     844258 :       scalar += ch;</span>
<span class="lineNum">      77 </span><span class="lineCov">     844258 :       if (ch != ' ' &amp;&amp; ch != '\t')</span>
<span class="lineNum">      78 </span><span class="lineCov">     814874 :         lastNonWhitespaceChar = scalar.size();</span>
<span class="lineNum">      79 </span>            :     }
<span class="lineNum">      80 </span>            : 
<span class="lineNum">      81 </span>            :     // eof? if we're looking to eat something, then we throw
<span class="lineNum">      82 </span><span class="lineCov">      43152 :     if (!INPUT) {</span>
<span class="lineNum">      83 </span><span class="lineCov">        338 :       if (params.eatEnd)</span>
<span class="lineNum">      84 </span><span class="lineCov">         26 :         throw ParserException(INPUT.mark(), ErrorMsg::EOF_IN_SCALAR);</span>
<span class="lineNum">      85 </span><span class="lineCov">        312 :       break;</span>
<span class="lineNum">      86 </span>            :     }
<span class="lineNum">      87 </span>            : 
<span class="lineNum">      88 </span>            :     // doc indicator?
<span class="lineNum">      89 </span><span class="lineCov">      44395 :     if (params.onDocIndicator == BREAK &amp;&amp; INPUT.column() == 0 &amp;&amp;</span>
<span class="lineNum">      90 </span><span class="lineCov">       1581 :         Exp::DocIndicator().Matches(INPUT))</span>
<span class="lineNum">      91 </span><span class="lineCov">        675 :       break;</span>
<span class="lineNum">      92 </span>            : 
<span class="lineNum">      93 </span>            :     // are we done via character match?
<span class="lineNum">      94 </span><span class="lineCov">      42139 :     int n = params.end-&gt;Match(INPUT);</span>
<span class="lineNum">      95 </span><span class="lineCov">      42139 :     if (n &gt;= 0) {</span>
<span class="lineNum">      96 </span><span class="lineCov">      23174 :       if (params.eatEnd)</span>
<span class="lineNum">      97 </span><span class="lineCov">       2415 :         INPUT.eat(n);</span>
<span class="lineNum">      98 </span><span class="lineCov">      23174 :       break;</span>
<span class="lineNum">      99 </span>            :     }
<span class="lineNum">     100 </span>            : 
<span class="lineNum">     101 </span>            :     // do we remove trailing whitespace?
<span class="lineNum">     102 </span><span class="lineCov">      18965 :     if (params.fold == FOLD_FLOW)</span>
<span class="lineNum">     103 </span><span class="lineCov">      14977 :       scalar.erase(lastNonWhitespaceChar);</span>
<span class="lineNum">     104 </span>            : 
<span class="lineNum">     105 </span>            :     // ********************************
<span class="lineNum">     106 </span>            :     // Phase #2: eat line ending
<span class="lineNum">     107 </span><span class="lineCov">      18965 :     n = Exp::Break().Match(INPUT);</span>
<span class="lineNum">     108 </span><span class="lineCov">      18965 :     INPUT.eat(n);</span>
<span class="lineNum">     109 </span>            : 
<span class="lineNum">     110 </span>            :     // ********************************
<span class="lineNum">     111 </span>            :     // Phase #3: scan initial spaces
<span class="lineNum">     112 </span>            : 
<span class="lineNum">     113 </span>            :     // first the required indentation
<span class="lineNum">     114 </span><span class="lineCov">      44604 :     while (INPUT.peek() == ' ' &amp;&amp; (INPUT.column() &lt; params.indent ||</span>
<span class="lineNum">     115 </span><span class="lineCov">       4339 :                                    (params.detectIndent &amp;&amp; !foundNonEmptyLine)))</span>
<span class="lineNum">     116 </span><span class="lineCov">       7510 :       INPUT.eat(1);</span>
<span class="lineNum">     117 </span>            : 
<span class="lineNum">     118 </span>            :     // update indent if we're auto-detecting
<span class="lineNum">     119 </span><span class="lineCov">      18965 :     if (params.detectIndent &amp;&amp; !foundNonEmptyLine)</span>
<span class="lineNum">     120 </span><span class="lineCov">        824 :       params.indent = std::max(params.indent, INPUT.column());</span>
<span class="lineNum">     121 </span>            : 
<span class="lineNum">     122 </span>            :     // and then the rest of the whitespace
<span class="lineNum">     123 </span><span class="lineCov">      25421 :     while (Exp::Blank().Matches(INPUT)) {</span>
<span class="lineNum">     124 </span>            :       // we check for tabs that masquerade as indentation
<span class="lineNum">     125 </span><span class="lineCov">       3874 :       if (INPUT.peek() == '\t' &amp;&amp; INPUT.column() &lt; params.indent &amp;&amp;</span>
<span class="lineNum">     126 </span><span class="lineCov">          2 :           params.onTabInIndentation == THROW)</span>
<span class="lineNum">     127 </span><span class="lineCov">          2 :         throw ParserException(INPUT.mark(), ErrorMsg::TAB_IN_INDENTATION);</span>
<span class="lineNum">     128 </span>            : 
<span class="lineNum">     129 </span><span class="lineCov">       3870 :       if (!params.eatLeadingWhitespace)</span>
<span class="lineNum">     130 </span><span class="lineCov">        642 :         break;</span>
<span class="lineNum">     131 </span>            : 
<span class="lineNum">     132 </span><span class="lineCov">       3228 :       INPUT.eat(1);</span>
<span class="lineNum">     133 </span>            :     }
<span class="lineNum">     134 </span>            : 
<span class="lineNum">     135 </span>            :     // was this an empty line?
<span class="lineNum">     136 </span><span class="lineCov">      18963 :     bool nextEmptyLine = Exp::Break().Matches(INPUT);</span>
<span class="lineNum">     137 </span><span class="lineCov">      18963 :     bool nextMoreIndented = Exp::Blank().Matches(INPUT);</span>
<span class="lineNum">     138 </span><span class="lineCov">      18963 :     if (params.fold == FOLD_BLOCK &amp;&amp; foldedNewlineCount == 0 &amp;&amp; nextEmptyLine)</span>
<span class="lineNum">     139 </span><span class="lineCov">        525 :       foldedNewlineStartedMoreIndented = moreIndented;</span>
<span class="lineNum">     140 </span>            : 
<span class="lineNum">     141 </span>            :     // for block scalars, we always start with a newline, so we should ignore it
<span class="lineNum">     142 </span>            :     // (not fold or keep)
<span class="lineNum">     143 </span><span class="lineCov">      18963 :     if (pastOpeningBreak) {</span>
<span class="lineNum">     144 </span><span class="lineCov">      18502 :       switch (params.fold) {</span>
<span class="lineNum">     145 </span>            :         case DONT_FOLD:
<span class="lineNum">     146 </span><span class="lineCov">        912 :           scalar += &quot;\n&quot;;</span>
<span class="lineNum">     147 </span><span class="lineCov">        912 :           break;</span>
<span class="lineNum">     148 </span>            :         case FOLD_BLOCK:
<span class="lineNum">     149 </span><span class="lineCov">       7428 :           if (!emptyLine &amp;&amp; !nextEmptyLine &amp;&amp; !moreIndented &amp;&amp;</span>
<span class="lineNum">     150 </span><span class="lineCov">       3879 :               !nextMoreIndented &amp;&amp; INPUT.column() &gt;= params.indent)</span>
<span class="lineNum">     151 </span><span class="lineCov">        536 :             scalar += &quot; &quot;;</span>
<span class="lineNum">     152 </span><span class="lineCov">       2079 :           else if (nextEmptyLine)</span>
<span class="lineNum">     153 </span><span class="lineCov">       1040 :             foldedNewlineCount++;</span>
<span class="lineNum">     154 </span>            :           else
<span class="lineNum">     155 </span><span class="lineCov">       1039 :             scalar += &quot;\n&quot;;</span>
<span class="lineNum">     156 </span>            : 
<span class="lineNum">     157 </span><span class="lineCov">       2615 :           if (!nextEmptyLine &amp;&amp; foldedNewlineCount &gt; 0) {</span>
<span class="lineNum">     158 </span><span class="lineCov">        506 :             scalar += std::string(foldedNewlineCount - 1, '\n');</span>
<span class="lineNum">     159 </span><span class="lineCov">        796 :             if (foldedNewlineStartedMoreIndented ||</span>
<span class="lineNum">     160 </span><span class="lineCov">        290 :                 nextMoreIndented | !foundNonEmptyLine)</span>
<span class="lineNum">     161 </span><span class="lineCov">        430 :               scalar += &quot;\n&quot;;</span>
<span class="lineNum">     162 </span><span class="lineCov">        506 :             foldedNewlineCount = 0;</span>
<span class="lineNum">     163 </span>            :           }
<span class="lineNum">     164 </span><span class="lineCov">       2615 :           break;</span>
<span class="lineNum">     165 </span>            :         case FOLD_FLOW:
<span class="lineNum">     166 </span><span class="lineCov">      14975 :           if (nextEmptyLine)</span>
<span class="lineNum">     167 </span><span class="lineCov">       1021 :             scalar += &quot;\n&quot;;</span>
<span class="lineNum">     168 </span><span class="lineCov">      13954 :           else if (!emptyLine &amp;&amp; !nextEmptyLine &amp;&amp; !escapedNewline)</span>
<span class="lineNum">     169 </span><span class="lineCov">      13197 :             scalar += &quot; &quot;;</span>
<span class="lineNum">     170 </span><span class="lineCov">      14975 :           break;</span>
<span class="lineNum">     171 </span>            :       }
<span class="lineNum">     172 </span>            :     }
<span class="lineNum">     173 </span>            : 
<span class="lineNum">     174 </span><span class="lineCov">      18963 :     emptyLine = nextEmptyLine;</span>
<span class="lineNum">     175 </span><span class="lineCov">      18963 :     moreIndented = nextMoreIndented;</span>
<span class="lineNum">     176 </span><span class="lineCov">      18963 :     pastOpeningBreak = true;</span>
<span class="lineNum">     177 </span>            : 
<span class="lineNum">     178 </span>            :     // are we done via indentation?
<span class="lineNum">     179 </span><span class="lineCov">      18963 :     if (!emptyLine &amp;&amp; INPUT.column() &lt; params.indent) {</span>
<span class="lineNum">     180 </span><span class="lineCov">       8340 :       params.leadingSpaces = true;</span>
<span class="lineNum">     181 </span><span class="lineCov">       8340 :       break;</span>
<span class="lineNum">     182 </span>            :     }
<span class="lineNum">     183 </span>            :   }
<span class="lineNum">     184 </span>            : 
<span class="lineNum">     185 </span>            :   // post-processing
<span class="lineNum">     186 </span><span class="lineCov">      32686 :   if (params.trimTrailingSpaces) {</span>
<span class="lineNum">     187 </span><span class="lineCov">      29746 :     std::size_t pos = scalar.find_last_not_of(' ');</span>
<span class="lineNum">     188 </span><span class="lineCov">      29746 :     if (lastEscapedChar != std::string::npos) {</span>
<span class="lineNum">     189 </span><span class="lineCov">       1639 :       if (pos &lt; lastEscapedChar || pos == std::string::npos)</span>
<span class="lineNum">     190 </span><span class="lineCov">        182 :         pos = lastEscapedChar;</span>
<span class="lineNum">     191 </span>            :     }
<span class="lineNum">     192 </span><span class="lineCov">      29746 :     if (pos &lt; scalar.size())</span>
<span class="lineNum">     193 </span><span class="lineCov">      29656 :       scalar.erase(pos + 1);</span>
<span class="lineNum">     194 </span>            :   }
<span class="lineNum">     195 </span>            : 
<span class="lineNum">     196 </span><span class="lineCov">      32686 :   switch (params.chomp) {</span>
<span class="lineNum">     197 </span>            :     case CLIP: {
<span class="lineNum">     198 </span><span class="lineCov">       2928 :       std::size_t pos = scalar.find_last_not_of('\n');</span>
<span class="lineNum">     199 </span><span class="lineCov">       2928 :       if (lastEscapedChar != std::string::npos) {</span>
<span class="lineNum">     200 </span><span class="lineCov">        901 :         if (pos &lt; lastEscapedChar || pos == std::string::npos)</span>
<span class="lineNum">     201 </span><span class="lineCov">        462 :           pos = lastEscapedChar;</span>
<span class="lineNum">     202 </span>            :       }
<span class="lineNum">     203 </span><span class="lineCov">       2928 :       if (pos == std::string::npos)</span>
<span class="lineNum">     204 </span><span class="lineCov">       1239 :         scalar.erase();</span>
<span class="lineNum">     205 </span><span class="lineCov">       1689 :       else if (pos + 1 &lt; scalar.size())</span>
<span class="lineNum">     206 </span><span class="lineCov">        334 :         scalar.erase(pos + 2);</span>
<span class="lineNum">     207 </span><span class="lineCov">       2928 :     } break;</span>
<span class="lineNum">     208 </span>            :     case STRIP: {
<span class="lineNum">     209 </span><span class="lineCov">      29752 :       std::size_t pos = scalar.find_last_not_of('\n');</span>
<span class="lineNum">     210 </span><span class="lineCov">      29752 :       if (lastEscapedChar != std::string::npos) {</span>
<span class="lineNum">     211 </span><span class="lineCov">       1639 :         if (pos &lt; lastEscapedChar || pos == std::string::npos)</span>
<span class="lineNum">     212 </span><span class="lineCov">        100 :           pos = lastEscapedChar;</span>
<span class="lineNum">     213 </span>            :       }
<span class="lineNum">     214 </span><span class="lineCov">      29752 :       if (pos == std::string::npos)</span>
<span class="lineNum">     215 </span><span class="lineCov">          6 :         scalar.erase();</span>
<span class="lineNum">     216 </span><span class="lineCov">      29746 :       else if (pos &lt; scalar.size())</span>
<span class="lineNum">     217 </span><span class="lineCov">      29656 :         scalar.erase(pos + 1);</span>
<span class="lineNum">     218 </span><span class="lineCov">      29752 :     } break;</span>
<span class="lineNum">     219 </span>            :     default:
<span class="lineNum">     220 </span><span class="lineCov">          6 :       break;</span>
<span class="lineNum">     221 </span>            :   }
<span class="lineNum">     222 </span>            : 
<a name="223"><span class="lineNum">     223 </span><span class="lineCov">      32686 :   return scalar;</span></a>
<span class="lineNum">     224 </span>            : }
<span class="lineNum">     225 </span><span class="lineCov">       6108 : }</span>
</pre>
      </td>
    </tr>
  </table>
  <br>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="ruler"><img src="../glass.png" width=3 height=3 alt=""></td></tr>
    <tr><td class="versionInfo">Generated by: <a href="http://ltp.sourceforge.net/coverage/lcov.php" target="_parent">LCOV version 1.11</a></td></tr>
  </table>
  <br>

</body>
</html>
